﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
//using Zhaoxi.CSharpDemo.CSharp6;
using static Zhaoxi.CSharpDemo.CSharp6.StudentServie; //引入带有静态成员的类
using static Zhaoxi.CSharpDemo.CSharp6.Color;         //引入枚举

using sharp5 = Zhaoxi.CSharpDemo.CSharp5; //给命名空间来一个别名
using Sharp6genericeInt = Zhaoxi.CSharpDemo.CSharp6.GenericClass<int>;
using Sharp6genericeString = Zhaoxi.CSharpDemo.CSharp6.GenericClass<string>;
using Sharp6genericeDatetime = Zhaoxi.CSharpDemo.CSharp6.GenericClass<System.DateTime>;

namespace Zhaoxi.CSharpDemo
{

    using Project = MyCompany.Project;
    public class CSharp6Info
    {
        //C# 在 3.0 版和 5.0 版对面向对象的语言添加了主要的新功能。 版本 6.0 随 Visual Studio 2015 一起发布
        public static void Show()
        {
            //静态导入
            { 
                //StudentServie.StudyStatic(); 
                StudyStatic(); //来自于StudentServie 的静方法
                //Id = 123;  //这里是静态属性
                Name = "这里是静态字段";

                Console.WriteLine($"Id={Id}");
                Console.WriteLine($"Name={Name}");
                 
                var red = Red;
                var green = Green;
                var blue = Blue;
                Console.WriteLine($"枚举Color.Red={red}");
                Console.WriteLine($"枚举Color.Green={green}");
                Console.WriteLine($"枚举Color.Blue={blue}");
            }
             
            //using 别名
            {
                Console.WriteLine("C#6版本 using 别名====================================================");
                Project.MyClass myclass = new Project.MyClass();

                Zhaoxi.CSharpDemo.CSharp5.UserInfo us = new Zhaoxi.CSharpDemo.CSharp5.UserInfo();
                sharp5.UserInfo user = new sharp5.UserInfo();

                Console.WriteLine("C#6版本 using 泛型类别名====================================================");
                Sharp6genericeInt genericIntClass = new Sharp6genericeInt();
                genericIntClass.Show(123456);

                Sharp6genericeString genericStringClass = new Sharp6genericeString();
                genericStringClass.Show("您好，这里是Charp6的Using 别名");

                Sharp6genericeDatetime genericDatetimeClass = new Sharp6genericeDatetime();
                genericDatetimeClass.Show(DateTime.Now);
            }
             
            //异常捕捉筛选
            {
                //try
                //{
                //    ShowExceptionType();
                //}
                //catch (Exception e) when (e.Message.Contains("002"))
                //{
                //    Console.WriteLine("这里是处理捕捉到的002的异常~");
                //}  
            }

            //自动属性初始化表达式
            {
                //直接在属性后面打等号  看 StudentServie.Id
                Console.WriteLine(Id);
                sharp5.UserInfo user = new sharp5.UserInfo();
                //表达式主体定义
                user.Name = "Richard老师";
                string userName = user.GetUserName();
            }

            //Null 条件运算符 ?. 和 ?[]
            {
                sharp5.UserInfo? user1 = null;

                //如果这个user1为null   user1.Name   //未将对象引用到实例
                //if (user1!=null)
                //{

                //}

                var userName1 = user1?.Name;  
                 
                user1 = new sharp5.UserInfo()
                {
                    Name = "张三"
                }; 
                var userName2 = user1?.Name;
            }

            //$ - 字符串内插
            {
                string text = "欢迎来到.NET 高级班进阶学习~"; 
                string hello = String.Format("你好：{0}",text);  
                StringBuilder stringBuilder=new StringBuilder();
                string result=  "" + ""; 
                string hello1 = $"你好：{text}"; 
            }


            //nameof 表达式
            Console.WriteLine(nameof(System.Collections.Generic));  // output: Generic
            Console.WriteLine(nameof(List<int>));  // output: List
            Console.WriteLine(nameof(List<int>.Count));  // output: Count
            Console.WriteLine(nameof(List<int>.Add));  // output: Add

            var numbers = new List<int> { 1, 2, 3 };
            Console.WriteLine(nameof(numbers));  // output: numbers
            Console.WriteLine(nameof(numbers.Count));  // output: Count
            Console.WriteLine(nameof(numbers.Add));  // output: Add
        }
    }


    namespace MyCompany
    {
        namespace Project
        {
            public class MyClass
            {

            }
        }
    }
}


